<!-- 在这个文件对每个tab对应的列表进行渲染 -->
<template>
	<view class="paryorder-content">
		<!-- 这里设置了z-paging加载时禁止自动调用reload方法，自行控制何时reload（懒加载）-->
		<!--  :enable-back-to-top="currentIndex===tabIndex" 在微信小程序上可以多加这一句，因为默认是允许点击返回顶部的，但是这个页面有多个scroll-view，会全部返回顶部，所以需要控制是当前index才允许点击返回顶部 -->
		<z-paging ref="paging" v-model="dataList" @query="queryList" :fixed="false" :auto="true">
			<template #top>
				<view class=""  >
					<fui-nav-bar title="我的销售商" isFixed isOccupy  @leftClick="pageBack">
						<template #right>
							<view class="u-p-r-20"  @click="$mRouter.push({route:'/pages/purchase/mySale/signHistory'})">
								签约记录
							</view>
						</template>
					</fui-nav-bar>
				</view>
			</template>
			<!-- 如果希望其他view跟着页面滚动，可以放在z-paging标签内 -->
			<view class="payorder-container" v-for="(item,index) in dataList" :key="index" >
				<view class="payorder-section">
					<image :src="item.logoUrl?item.logoUrl:defaultLogo" mode="" class="section-image" ></image>
					<view class="section-list">
						<view class="section-item">
							<view class="section-item-name">{{item.name}}</view>
							<view class="section-item-count u-m-b-10">
								<text class="u-font-28" style="color: #999;">已签约  {{item.numberOfContractedItems}} 个单品</text>
							</view>
						</view>
					</view>
					<view class="u-flex u-col-center u-row-between u-m-l-20" style="height: 100%;">
						<view class="section-btn-box" @click="goStatDetails(item)">
							<image src="/static/xiaoshou/contractManger.png" mode="" style="height: 46rpx;width: 43rpx;" ></image>
							<text class="btn-text">查看合约</text>
						</view>
					</view>
					
				</view>
			</view>
			
		</z-paging>
		<view class="shop-cart-container" @click="goScanPageFn">
			<fui-icon name="scan" style="font-size: 50rpx;font-weight: bold;"></fui-icon>
			<text class="u-font-22" style="width: 100%;text-align: center;">去签约</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//v-model绑定的这个变量不要在分页请求结束中自己赋值！！！
				dataList: [],
				searchText:'',
			}
		},
		created(){
		},
		onShow(){
			this.$nextTick(()=>{
				this.$refs.paging.reload();
			})
		},
		methods: {
			goScanPageFn(){
				// #ifdef APP-PLUS
					uni.scanCode({
						success:  (res) => {
							// this.$mRouter.push({ route: '/pages/sale/signContract/index?qrcode='+res.result });
							this.$mHelper.delayedJump(`/pages/purchase/mySale/signContract?qrcode=${res.result}`,'push',1000);
						},
						fail:(Error)=>{
							console.log(Error);
							this.$u.toast('识别二维码失败')
						},
						complete:(complete)=>{
							console.log(complete);
						}
					});
					// this.$mRouter.push({route:'/pages/purchase/mySale/signContract'})
				// #endif
				// #ifndef APP-PLUS
					this.$mRouter.push({route:'/pages/purchase/mySale/scan'})
				// #endif
			},
			goStatDetails(data){
				this.$mRouter.push({
					route: '/pages/purchase/mySale/saleDetails?data='+JSON.stringify(data) 
				})
			},
			async queryList(pageNo, pageSize) {
				//组件加载时会自动触发此方法，因此默认页面加载时会自动触发，无需手动调用
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				//模拟请求服务器获取分页数据，请替换成自己的网络请求
				const params = {
					pageIndex: pageNo,
					pageSize: pageSize,
				}
				uni.showLoading({
					title: 'loading...',
					mask: false
				});
				const res = await this.$newHttp.get('api/v1.2/Shop/PurchaseGetSellersByPage', { params: params } );
				uni.hideLoading({
					title: 'loading...'
				})
				if(res.code === 200){
					this.$refs.paging.complete(res.data.list);
				}else{
					this.$refs.paging.complete(false);
				}
			},
			itemClick(item) {
				console.log('点击了', item.title);
				this.$mRouter.push({ 
					route: '/pages/sale/payorder/createPayOrder?shop='+item.id,
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/static/iconfont/iconfont.css';
	/* 注意:父节点需要固定高度，z-paging的height:100%才会生效 */
	.paryorder-content {
		height: 100%;
		
	}
	.payorder-container{
		background-color: #fff;
		box-sizing: border-box;
		padding: 0 30rpx;
		.payorder-header{
			display: flex;
			justify-content: space-between;
		}
		.payorder-section{
			display: flex;
			align-items: center;
			box-sizing: border-box;
			padding: 35rpx 0;
			margin-bottom: 20rpx;
			.section-image{
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
				margin-right: 32rpx;
			}
			.section-list{
				flex: 1;
				margin-left: 20rpx;
				
				.section-item{
					width: 100%;
					.section-item-name{
						font-size: 32rpx;
						font-weight: 500;
						margin-bottom: 10rpx;
					}
					.section-item-count{
						font-size: 24rpx;
						color: #999;
					}
					.section-btn{
						width: 160rpx;
						margin-left: 10rpx;
						height:70rpx;
						border-radius: 35rpx;
						border: 1rpx solid #FFBB1A;
						color: #FFBB1A;
						text-align: center;
						line-height: 70rpx;
					}
					.section-btn-disabled{
						border-color:#999999;
						color: #999999;
					}
				}
			}
			.section-btn-box{
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				>.btn-text{
					font-size: 20rpx;
					margin-top: 10rpx;
				}
			}
		}
		
	}
	.shop-cart-container{
		position: fixed;
		bottom: 100rpx; 
		right: 40rpx; 
		width: 120rpx; 
		height: 120rpx; 
		border-radius: 50%; 
		background-color: #FFBB1A;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-wrap: wrap;
		align-content: center;
		box-shadow: 0px 0px 18px 2px rgba(6,0,1,0.1);
		transition: all 0.5s ease;
		z-index: 999;
	}

</style>
